#include "precompiled.h"
#include "eqvdialog.h"
using namespace std;
using namespace weo::engine::item;
using namespace weo::ui;
EQVDialog::EQVDialog(QWidget* parent /*= 0*/, Qt::WFlags flags /*= 0*/) : QDialog(parent, flags)
{
    setupUi(this);
}
void EQVDialog::setAttributes(const std::vector<std::string>& value, unsigned int start, unsigned int stop)
{
    if(stop == 0) stop = value.size();
    m_Attributes.resize(stop-start);
    std::copy(value.begin()+start,value.begin()+stop ,m_Attributes.begin());
    QStringList qsl;
    for(unsigned int i = 0;i<m_Attributes.size();i++)
    {
        qsl += tr(m_Attributes[i].c_str());
    }
    EQVTableWidget->setColumnCount(m_Attributes.size());
    EQVTableWidget->setRowCount(m_Attributes.size());
    EQVTableWidget->setHorizontalHeaderLabels(qsl);
    EQVTableWidget->setVerticalHeaderLabels(qsl);
}
void EQVDialog::calcEQV()
{
    m_Character->evaluateBuffs();
    m_Character->evaluateEquip(m_Equip.Items,m_Equip.Gems,m_Equip.Enchants);
    double basevalue = m_Character->evaluateTF();
    std::vector<double> indivvalues;
    for(unsigned int i = 0;i<m_Attributes.size();i++)
    {
        Attribute *attr = new Attribute(Attribute::getAttributeValue(m_Attributes[i]),10.0f);
        m_Character->evaluateBuffs();
        m_Character->evaluateEquip(m_Equip.Items,m_Equip.Gems,m_Equip.Enchants);
        m_Character->addAttribute(*attr);
        indivvalues.push_back((double)m_Character->evaluateTF()-basevalue);
    }
    for(unsigned int i = 0;i<indivvalues.size();i++)
    {
        for(unsigned int k = 0;k<indivvalues.size();k++)
        {
            double value = indivvalues[i]/indivvalues[k];
            if(indivvalues[i] <= 0.01f || indivvalues[k] <= 0.01f)
            {
                double value = 0;
            }
            QTableWidgetItem *newItem = new QTableWidgetItem(QString::number(value));
            newItem->setFlags(0);
            EQVTableWidget->setItem(i,k,newItem);
        }
    }
}